package com.dd.stack.redis.config.redisConfig;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/8/17 16:22
 * @Description RedisKey工厂
 */
// RedisKeyFactory.java - 新增allDataObjectsKey方法
public class RedisKeyFactory {

    // 延迟操作时间，根据业务场景调整，通常为几百毫秒到几秒
    public static final Long DELAY_MILLISECONDS = 500L;

    private static final String SEPARATOR = ":";

    /******************** data_object相关 ********************/
    private static final String DATA_OBJECT = "data_object";

    /******************** product相关 ********************/
    private static final String PRODUCT = "product";
    private static final String PRODUCT_COUNTER = PRODUCT + SEPARATOR + "counter";

    /******************** 排行榜 ********************/
    private static final String LEADERBOARD = "leaderboard";

    /**
     * 根据DataObject的id生成单个对象的key
     */
    public static String singleDataObjectKey(Long id) {
        return DATA_OBJECT + SEPARATOR + "id" + SEPARATOR + id;
    }

    /**
     * 所有DataObject列表的缓存Key
     */
    public static String allDataObjectsKey() {
        return DATA_OBJECT + SEPARATOR + "all";
    }

    /**
     * 根据Product的id生成单个对象的key
     */
    public static String singleProductKey(Long id) {
        return PRODUCT + SEPARATOR + id;
    }

    /**
     * 根据Product的id生成ProductCounter的key
     */
    public static String productCounterKey(Long id) {
        return PRODUCT_COUNTER + SEPARATOR + id;
    }

    /**
     * 用户排行榜Key
     */
    public static String userLeaderboardKey() {
        return LEADERBOARD + SEPARATOR + "user";
    }
}
